//购物车查询列表 0

define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";
	
	var wind_async=require('ddf_wind_async');

	var base=require('component-base');
	
	require('component-page');
	
	var dialog=require('component-dialog');
	
	var history = require('component-history');

var mobile='',merchandiseName='';

var tips_index=0;

/**
 * 查询列表
 */
exports.init=function(m) {
	history.addHis(this,arguments);
	
	resetSearchParams();
	window.$ddf_cart = m;
	
	var htmlStr="";
	
    	htmlStr += '<div id="content-header">';
    	htmlStr += '<div id="breadcrumb"> <a href=javascript:$ddf_base.load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="#" class="current">购物车查询</a></div>';
    	htmlStr += '</div>    ';
    	htmlStr += '<div class="container-fluid">';
    	htmlStr += '<div class="row-fluid">';
    	htmlStr += '<div class="span12">';
    	
    	htmlStr += '<div id="alert-tips0" ></div>';
    	
    	htmlStr += '<div class="widget-box">';
    	htmlStr += '<div class="widget-title">';
    	htmlStr += '<span class="icon">';
    	htmlStr += '<i class="icon-search"></i>';
    	htmlStr += '</span>';
    	htmlStr += '<h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button>';
    	htmlStr += '</div> ';    	    	
    	htmlStr += '<div class="widget-content nopadding">';
    	htmlStr += '<form class="form-horizontal">';  
    	
    	htmlStr += '<div class="row-fluid">';
    	
    	/*htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">商家名称：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="shopName"/> ';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';*/
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">手机号码：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="mobile"/> ';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">商品名称：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="merchandiseName"/> ';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '</div>';   
    	
    	
    	htmlStr += '<div class="form-actions">';
    	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_cart.searchCart()">搜索</button>';
    	htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_cart.resetSearchParams()">重置</button>';
    	htmlStr += '</div>';
    	htmlStr += '</form>';
    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="widget-box">';
    	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
    	htmlStr += '<h5>购物车列表</h5>';
    	htmlStr += '</div>';
    	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
    	htmlStr += '<table class="table table-bordered data-table record">';
    	htmlStr += '<thead>';
    	htmlStr += '<tr>';
    	htmlStr += '<th>序号</th>';
    	htmlStr += '<th>购物车代码</th>';
    	htmlStr += '<th>用户手机号</th>';
    	htmlStr += '<th>商家名称</th>';
    	htmlStr += '<th>商品名称</th>';
    	htmlStr += '<th>商品条码</th>';
    	htmlStr += '<th>加入时间</th>';
    	htmlStr += '</tr>'; 
    	htmlStr += '</thead>';
    	htmlStr += '<tbody id="cartList">';
    	
    	htmlStr += '</tbody>';
    	htmlStr += '</table>';
    	
    	htmlStr += '<div id="footPageDiv0">';
    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	showDiv("content0");
    	
    	$("#content0").html(htmlStr);
    	
	
    	getQueryCart(1,10,mobile,merchandiseName);
    	
	
}


/**
 * 查询列表
 * @param beginDate
 * @param endDate
 * @param terminal
 */
function getQueryCart(pageNumber,pageSize,mobile,merchandiseName){
	
	
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize":pageSize,
			"mobile":mobile,
			"merchandiseName":merchandiseName
	        };
	tips_index=0;

	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.cart.getCartList,params));
		
		loadqueryCartListCallBack(data);
		
	}))().start();
	
}

function loadqueryCartListCallBack(data){
	if(data["code"]==1){
		
    	
    	var htmlStr="";
    	
    	for(var i=0;i<data["cartListData"].length;i++){
    		htmlStr += ' <tr>';
    		htmlStr += '<td>'+base.getSequence(data["pageNumber"],data["pageSize"],i+1)+'</td>';
    		htmlStr += '<td>'+data["cartListData"][i]["CART_ID"]+' </td>';
    		htmlStr += '<td>'+data["cartListData"][i]["mobile"]+' </td>';
    		htmlStr += '<td>'+data["cartListData"][i]["shop_name"]+' </td>';
    		htmlStr += '<td>'+data["cartListData"][i]["merchandise_name"]+' </td>';
    		htmlStr += '<td>'+data["cartListData"][i]["barcode"]+' </td>';
    		htmlStr += '<td>'+data["cartListData"][i]["CREATE_TIME"]+' </td>';
    		htmlStr += '</tr> ';
    		
    	}
    	$("#cartList").html(htmlStr);
    	
    	$('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
			 
    		changePageCallback:function(pageSize,page){  
    			getQueryCart(page,pageSize,mobile,merchandiseName);
			 },
			 changePageSizeCallBack:function(pageSize){
				 getQueryCart(1,pageSize,mobile,merchandiseName);
			 } 
         }); 

	}else{
		
		 
		 base.tips_error(data["message"])

		
	}

	base.cancelLoading();
}




/**
 * 重置参数
 */
function resetSearchParams(){
	
	mobile = '';
	merchandiseName = '';
	
	$("#mobile").val("");
	$("#merchandiseName").val("");
	
}

/**
 * 搜索
 */
function searchCart(){
	

	mobile = $("#mobile").val();
	merchandiseName = $("#merchandiseName").val();
	
	tips_index=0;
	
	getQueryCart(1,10,mobile,merchandiseName);
	
}



function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block=="content0"){
		shopTypeId="";
	}
	

	
}



//暴露方法
exports.getQueryCart=getQueryCart;
exports.loadqueryCartListCallBack=loadqueryCartListCallBack;
exports.resetSearchParams=resetSearchParams;
exports.searchCart=searchCart;

exports.showDiv=showDiv;

});
